_realname=maxflow
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.0.5
pkgrel=2
pkgdesc="A library implementing the max-flow/min-cut algorithm (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/gerddie/maxflow'
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/gerddie/${_realname}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-pc-file-escaping.patch")
sha256sums=('e73a7be173fb95e93366c8128f9f478bc2fe406f7f83eb998fc34e18eaabb612'
            'c141c2529ad3435648a1e15c55fd6f280ef47cc80957807b0eaf816632b0658b')

prepare() {
  cd ${_realname}-${pkgver}

  # https://github.com/gerddie/maxflow/pull/5
  patch -p1 -i "${srcdir}/0001-fix-pc-file-escaping.patch"
}

build() {
  mkdir "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
}
